/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t__ora_malloc.c                                    */
/*  NOTE      =                                                    */
/*  DATE      = 2016/03/14 by songbb                               */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"

#include "../../../../src/module/oracle/config.h"
#include <oracle/ora_core.h>
#include <oracle/comm/ora_comm.h>

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

/**
 * 正常测试
 */
static void __case1(void)
{
    char *p_buffer = NULL;
    p_buffer = (char *) __ora_malloc(1, 1);
    CU_ASSERT_PTR_NOT_NULL(p_buffer);

    ora_free((void **) &p_buffer);
}

/**
 * 异常测试
 */
static void __case2(void)
{
    char *p_buffer = NULL;
    p_buffer = (char *) __ora_malloc(0, 1);
    CU_ASSERT_PTR_NULL(p_buffer);
}

/**
 * 异常测试
 */
static void __case3(void)
{
    char *p_buffer = NULL;
    p_buffer = (char *) __ora_malloc(APM_ORA_MEM_MAX_SIZE + 2, APM_ORA_MEM_MAX_SIZE + 1);
    CU_ASSERT_PTR_NULL(p_buffer);
}

int add_suite__ora_malloc(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __ora_malloc()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
